package action;

import controller.Action;
import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import model.Aluno;
import model.Curso;
import state.StateFactory;
import util.ConverteData;
import util.Estados;

public class EditarAlunoAction extends ManterAlunoAction {

    @Override
    public void setParametros(HttpServletRequest request, HttpServletResponse response) throws ServletException {
        try {

            int matriculaAluno = Integer.parseInt(request.getParameter("matricula"));
            Aluno aluno = Aluno.obterAluno(matriculaAluno);

            if (aluno.getStatus() == null || aluno.getStatus().equals("")) {
                aluno.setStatus("Matriculado");
            }
            aluno.alunoState = StateFactory.create(aluno.getStatus());

            request.setAttribute("matricular", !aluno.alunoState.matricular());
            request.setAttribute("trancar", !aluno.alunoState.trancar());
            request.setAttribute("formar", !aluno.alunoState.formar());
            request.setAttribute("jubilar", !aluno.alunoState.jubilar());

            request.setAttribute("aluno", aluno);

        } catch (SQLException e) {
            throw new ServletException(e);
        } catch (ClassNotFoundException e) {
            throw new ServletException(e);
        }
    }

    @Override
    public void efetuaPersistencia(Aluno aluno) throws ServletException {
        try {
            aluno.editar();
        } catch (SQLException e) {
            throw new ServletException(e);
        } catch (ClassNotFoundException e) {
            throw new ServletException(e);
        }
    }

}
